import java.awt.Point;
import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Vector;

public class Main {

	/**
	 * @param args
	 */
	static Point startPos;

	/**
	 * Contains the map without the box and the player position
	 */
	public static char[][] map;

	/**
	 * Contains all the goal positions
	 */
	public static HashSet<Point> goals;

	/**
	 * Contains all deadlock positions
	 */
	public static HashSet<Point> deadLock_positions;
	
	public static ArrayList<Pattern> patterns = new ArrayList<Pattern>();

	public static void main(String[] args) throws IOException {
		Vector<String> board = new Vector<String>();

//		board.add("#######");
//		board.add("#  $$ #");
//		board.add("#     #");
//		board.add("#   @ #");
//		board.add("#.$   #");
//		board.add("#.   .#");
//		board.add("#######");

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String line;
		while (br.ready()) {
			line = br.readLine();
			board.add(line);
		} // End while

		ArrayList<Point> boxes = new ArrayList<Point>();
		goals = new HashSet<Point>();
		// Creating the map
		map = new char[board.size()][];
		for (int i = 0; i < board.size(); i++) {
			line = board.get(i);
			map[i] = new char[line.length()];
			map[i] = line.toCharArray();
			for (int j = 0; j < map[i].length; j++) {
				char c = map[i][j];

				if (c == '$') {
					boxes.add(new Point(i, j));
					map[i][j] = ' ';

				} else if (c == '*') {
					boxes.add(new Point(i, j));
					goals.add(new Point(i, j));
					map[i][j] = '.';

				} else if (c == '+') {
					startPos = new Point(i, j);
					goals.add(new Point(i, j));
					map[i][j] = '.';

				} else if (c == '@') {
					startPos = new Point(i, j);
					map[i][j] = ' ';

				} else if (c == '.') {
					goals.add(new Point(i, j));
				}
			}
		} // End create map

		staticDeadlock();
		addPatterns();

		// Create start state
		GameState startState = new GameState(boxes, null, startPos,0.0);

		// Find path main fcuntion
		String path = findPath(startState);
		System.out.println(path);
	} // main

	/**
	 * Change the character of the map to 'd' if the cell is a deadlock Pattern
	 * : #d d# d# #d
	 */
	public static void staticDeadlock() {
		deadLock_positions = new HashSet<Point>(20);
		
		GameState emptyState = new GameState(new ArrayList<Point>(), null, startPos,0.0);
		for (int row = 0; row < map.length; row++) {
			for (int col = 0; col < map[row].length; col++) {
				Point toCheck = new Point(row,col);
				if(map[row][col] == ' ' && emptyState.possibleMovesBox(toCheck).equals("")){
					deadLock_positions.add(toCheck);
				}
			}
		}
		// for (int row = 0; row < map.length; row++) {
		// for (int col = 0; col < map[row].length; col++) {
		// char c = map[row][col];
		//
		// // Borders and corners
		// if (c == '#') {
		//
		// if ((col != 0) && (row + 1 != map.length)
		// && map[row + 1][col - 1] == '#') {
		//
		// // Left up corner
		// if (map[row + 1][col] == ' ') {
		// deadLock_positions.add(new Point(row + 1, col));
		// }
		// // Right down corner
		// if (map[row][col - 1] == ' ') {
		// deadLock_positions.add(new Point(row, col - 1));
		// }
		//
		// }// else if?
		// if ((col + 1 != map[0].length) && (row + 1 != map.length)
		// && map[row + 1][col + 1] == '#') {
		//
		// // Right up corner
		// if (map[row + 1][col] == ' ') {
		// deadLock_positions.add(new Point(row + 1, col));
		// }
		//
		// // Left down corner
		// if (map[row][col + 1] == ' ') {
		// deadLock_positions.add(new Point(row, col + 1));
		// }
		//
		// }
		//
		// }
		//
		// }
		// }

	}

	public static String findPath(GameState startState) {
		GameState goalState = findGoal(startState);
		return writePath(goalState);
	}

	/**
	 * find the goal using Breadth First schearch algorithm, need to implement
	 * the hashcode and equal methods in GameState to avoid checking similar
	 * state multiple time.
	 * 
	 * @param startState
	 *            initial state of the map
	 * @return
	 */
	public static GameState findGoal(GameState startState) {
		PriorityQueue<GameState> queue = new PriorityQueue<GameState>();
		HashSet<GameState> checkedState = new HashSet<GameState>();
		queue.add(startState);
		checkedState.add(startState);
		while (!queue.isEmpty()) {
			GameState tempState = queue.poll();
			System.out.println("deadlock: " + tempState.isDeadlock());
			tempState.print();
			if (tempState.isGoalState()) {
				return tempState;
			} else {
				for (GameState childState : tempState.findChildren()) {
					if (checkedState.add(childState)) {
						if(!childState.isDeadlock()){
						queue.add(childState);
						}
					}

				}
			}

		}
		return null;
	}

	public static String writePath(GameState goal) {
		String path = "";

		while (goal != null) {
			path = goal.getPartialPath() + path;
			if (goal.parent == null) {
				goal = null;
			} else {
				goal = goal.parent;
			}
		}

		return path;
	}
	
	public static void addPatterns(){
		ArrayList<Point> empty = new ArrayList<Point>();
		ArrayList<Point> pattBoxes = new ArrayList<Point>();
		ArrayList<Point> walls = new ArrayList<Point>();
		
		//$$
		//$$
		
		
		Point p1 = new Point(0,0);
		Point p2 = new Point(0,1);
		Point p3 = new Point(1,0);
		Point p4 = new Point(1,1);
		
		pattBoxes.add(p1);
		pattBoxes.add(p2);
		pattBoxes.add(p3);
		pattBoxes.add(p4);
		
		patterns.add(new Pattern(pattBoxes, empty, 4));
		
		pattBoxes = new ArrayList<Point>();
		
		p1 = new Point(0,0);
		p2 = new Point(1,0);
		
		p3 = new Point(0,1);
		p4 = new Point(1,1);
		
		pattBoxes.add(p1);
		pattBoxes.add(p2);
		walls.add(p3);
		walls.add(p4);
		
		patterns.add(new Pattern(pattBoxes, walls, 2));
		
		pattBoxes = new ArrayList<Point>();
		walls = new ArrayList<Point>();
		
		p1 = new Point(0,0);
		p2 = new Point(0,1);
		
		p3 = new Point(-1,0);
		p4 = new Point(-1,1);
		
		pattBoxes.add(p1);
		pattBoxes.add(p2);
		walls.add(p3);
		walls.add(p4);
		
		patterns.add(new Pattern(pattBoxes, walls, 2));
		
		pattBoxes = new ArrayList<Point>();
		walls = new ArrayList<Point>();
		
		p1 = new Point(0,0);
		p2 = new Point(1,0);
		
		p3 = new Point(0,-1);
		p4 = new Point(1,-1);
		
		pattBoxes.add(p1);
		pattBoxes.add(p2);
		walls.add(p3);
		walls.add(p4);
		
		patterns.add(new Pattern(pattBoxes, walls, 2));
		
		pattBoxes = new ArrayList<Point>();
		walls = new ArrayList<Point>();
		
		p1 = new Point(0,0);
		p2 = new Point(0,1);
		
		p3 = new Point(1,0);
		p4 = new Point(1,1);
		
		pattBoxes.add(p1);
		pattBoxes.add(p2);
		walls.add(p3);
		walls.add(p4);
		
		patterns.add(new Pattern(pattBoxes, walls, 2));
		
		pattBoxes = new ArrayList<Point>();
		walls = new ArrayList<Point>();
		
		p1 = new Point(0,0);
		p2 = new Point(1,-1);
		
		p3 = new Point(-1,0);
		p4 = new Point(-1,-1);
		Point p5 = new Point(0,-2);
		Point p6 = new Point(1,-2);
		
		pattBoxes.add(p1);
		pattBoxes.add(p2);
	
		walls.add(p3);
		walls.add(p4);
		walls.add(p5);
		walls.add(p6);
		
		patterns.add(new Pattern(pattBoxes, walls, 2));
		
		pattBoxes = new ArrayList<Point>();
		walls = new ArrayList<Point>();
		
		p1 = new Point(0,0);
		p2 = new Point(1,-1);
		
		p3 = new Point(2,-1);
		p4 = new Point(2,0);
		p5 = new Point(1,1);
		p6 = new Point(0,-1);
		
		pattBoxes.add(p1);
		pattBoxes.add(p2);
	
		walls.add(p3);
		walls.add(p4);
		walls.add(p5);
		walls.add(p6);
		
		patterns.add(new Pattern(pattBoxes, walls, 2));
		
		pattBoxes = new ArrayList<Point>();
		walls = new ArrayList<Point>();
		
		p1 = new Point(0,0);
		p2 = new Point(1,1);
		
		p3 = new Point(-1,0);
		p4 = new Point(-1,1);
		p5 = new Point(0,2);
		p6 = new Point(1,2);
		
		pattBoxes.add(p1);
		pattBoxes.add(p2);
	
		walls.add(p3);
		walls.add(p4);
		walls.add(p5);
		walls.add(p6);
		
		patterns.add(new Pattern(pattBoxes, walls, 2));
		
		pattBoxes = new ArrayList<Point>();
		walls = new ArrayList<Point>();
		
		p1 = new Point(0,0);
		p2 = new Point(1,1);
		
		p3 = new Point(0,-1);
		p4 = new Point(1,-1);
		p5 = new Point(2,0);
		p6 = new Point(2,1);
		
		pattBoxes.add(p1);
		pattBoxes.add(p2);
	
		walls.add(p3);
		walls.add(p4);
		walls.add(p5);
		walls.add(p6);
		
		patterns.add(new Pattern(pattBoxes, walls, 2));
		
	}
	
} // End Main
